package kr.hyunist.androidcomplete01saeildamil.ch12;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.*;

public class SpinnerEx2 extends Activity {
	String[] names = { "mike", "angel", "crow", "john", "ginie", "sally", "cohen", "rice" };
	TextView tv;
	boolean mInit = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.spinnerex2);

		ArrayAdapter<String> sAdapter = new ArrayAdapter<String>(
				SpinnerEx2.this, android.R.layout.simple_spinner_dropdown_item, names);
		
		sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		Spinner spin = (Spinner) findViewById(R.id.spinnerex2spinner);
		spin.setAdapter(sAdapter);
		
		spin.setOnItemSelectedListener(new OnItemSelectedListener() {
			
			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				if(mInit == false){
					mInit = true;
					return;
				}
				tv = (TextView) findViewById(R.id.spinnerex2tv);
				tv.setText(names[position]);
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {				
			}
			
		});
		
	}
}
